package com.ccb.sc.member.controller;

import com.ccb.sc.auth.TokenAuth;
import com.ccb.sc.auth.TokenModel;
import com.ccb.sc.member.service.WishingBottleService;
import com.ccb.sc.member.vo.WishingBottleCreateVo;
import com.ccb.sc.member.vo.WishingBottleListVo;
import com.ccb.sc.common.bind.annotation.CurrentUser;
import com.ccb.sc.common.bind.page.PageParams;
import com.ccb.sc.common.bind.page.PageVo;
import com.ccb.sc.common.bind.response.ResBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author ken
 * @version 1.0
 * @date 2022/8/14 16:30
 */
@RestController
@TokenAuth
@RequestMapping("/app/wishing-bottle")
@Api(value = "许愿瓶管理", tags = "许愿瓶管理")
public class WishingBottleController {

    @Autowired
    private WishingBottleService wishingBottleService;

    @GetMapping("/list")
    @ApiOperation(value = "我的许愿瓶", response = WishingBottleListVo.class, responseContainer = "list")
    public ResBody<?> list(@CurrentUser @ApiIgnore TokenModel token, PageParams queryParam) {
        PageVo<WishingBottleListVo> result = this.wishingBottleService.selectWishingBottleList(token.getId(), queryParam);
        return ResBody.success(result);
    }

    @PostMapping("/create")
    @ApiOperation(value = "放入许愿瓶")
    public ResBody<?> create(@CurrentUser @ApiIgnore TokenModel token, @Validated @RequestBody WishingBottleCreateVo createVo) {
        this.wishingBottleService.create(token.getId(), createVo);
        return ResBody.success();
    }

}
